<br />
<div class="col-lg-9">
	<h1>Usuários</h1>  
</div>
<div class="col-lg-3 right">
	<br />
	<%= link_to 'Adicionar Usuário', new_user_path, class: 'btn btn-primary btn-block' %>  
</div>

<div class="content-panel">
	<table class="table table-striped table-advance table-hover">
  		<thead>
        	<tr>
            	<th> Nome </th>
              	<th> E-mail </th>
              	<th> Permissôes </th>
              	<th> Status </th>
              	<th>  </th>
          	</tr>
        </thead>
        <tbody>
        	<% @users.each do |user| %>
        		<tr>
        			<td><%= user.name %></td>
        			<td><%= user.email %></td>
        			<td><%= user.permission %></td>
        			<td>
        				<% if user == session[:current_user] %>
	        				<%= '<span class="label label-success label-mini"> Ativo </span>'.html_safe if user.active %>
	        				<%= '<span class="label label-warning label-mini"> Inativo </span>'.html_safe unless user.active %>
        				<% else %>
	        				<%= link_to '<span class="label label-success label-mini"> Ativo </span>'.html_safe, user_status_change_path(user) if user.active %>
	        				<%= link_to '<span class="label label-warning label-mini"> Inativo </span>'.html_safe, user_status_change_path(user) unless user.active %>
        				<% end %>
        			</td>
        			<td>
        				<%= link_to '<i class="fa fa-pencil"></i>'.html_safe, edit_user_path(user), class: 'btn btn-primary btn-xs' %>
        				<%= link_to '<i class="fa fa-trash-o "></i>'.html_safe, user_destroy_path(user), id: "delete-#{user.id}",  class: 'btn btn-danger btn-xs'  unless user == session[:current_user]%>
        				<script type="text/javascript">
							$(document).ready(function () {
								$("#delete-<%= user.id %>").click(function( e ){
								   if(!confirm('Você realmente deseja remover este registro?')) {
								      e.preventDefault();		      
								   }
								});
							});
						</script>
        			</td>
        		</tr>
    		<% end %>    	
        </tbody>
    </table>
</div>
